from bs4 import BeautifulSoup
import requests
#爬取优美图库并下载

#参数
param = {

}
#代理
agent = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"
}

url="https://www.umei.cc/"
response=requests.get(url=url,headers=agent)
htmlContent=response.content.decode("utf-8")
soup=BeautifulSoup(htmlContent,"html.parser")
#养眼美女  清纯美女....
mv=soup.find("div",class_="SpecBox")
#遍历导航
list=mv.find_all("li")
for i in list:
        urlList="https://www.umei.cc"+list[0].a.get("href")
response2=requests.get(urlList,headers=agent)
beautifulGirl=response2.content.decode("utf-8")
soup2=BeautifulSoup(beautifulGirl,"html.parser")
bDiv=soup2.find("div",class_="TypeList")
bLi=bDiv.find_all("li")
imgUrl=[]
for i in bLi:
        imgUrl.append(i.img.get("src"))

def download(imgUrl):
        num=0
        for i in imgUrl:
                num+=1
                numStr=repr(num)
                str='C:\\Users\\指鹿\\Desktop\\img\\img'+numStr+'.png'
                f=requests.get(i,headers=agent,stream=True)
                if f.status_code == 200:
                         open(str,'wb').write(f.content)
                         print("img"+numStr+"下载完成")
                         f.close()
download(imgUrl)
#beautifulLi=soup.find_all("li")
#print(soup2.prettify())
response2.close()
response.close()